<template>
    <div class="my_data_out">
      <div class="same_title postion">
        <a href="#" @click="back">
          <img src="../../static/img/back.png" alt="">
        </a>
        我的借款
      </div>
      <div class="position_placeholder"></div>
      <div class="loan_list_out">
        <div class="loan_list" v-for="(item,index) in applyData">
          <el-row class="loan_line">
            <el-col :xs="8">
              <img :src="imgUrl[index]" alt="" onerror="this.src='./static/img/mine-icon1.png'">
              <!--<img :src="(JSON.parse(item.images))[0].imageUrl" alt="" onerror="this.src='../../static/img/mine-icon1.png'">-->
              {{item.productName}}
            </el-col>
            <el-col :xs="16" class="loan_date" >
              {{item.applyTime}}申请
            </el-col>
          </el-row>
          <el-row class="loan_bottom">
            <el-col :xs="18" class="loan_status">{{item.loanUse}}</el-col>
            <el-col :xs="6">
              <!--<a href="javascript:;" v-if="item.isSend == 0">未发送</a>-->
              <!--<a href="javascript:;" v-if="item.isSend == 1">已发送</a>-->
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
</template>

<script>
    import {urlList} from '../assets/urlList.js'//引入接口地址文件
    function getCookie(cname)
    {
      var name = cname + "=";
      var ca = document.cookie.split(';');
      for(var i=0; i<ca.length; i++)
      {
        var c = ca[i].trim();
        if (c.indexOf(name)==0) return c.substring(name.length,c.length);
      }
      return "";
    }
    let auth = getCookie('USER_P2P_H5_COOKIE');

    function GetQueryString(name)
    {
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      var r = decodeURI(window.location.search.substr(1)).match(reg);
      if(r!=null)return  unescape(r[2]); return null;
    }
    let channelNum = GetQueryString("channelNum")
    if(!channelNum){
      channelNum = 0
    }

    console.log(GetQueryString('channelNum'))
    let params = new URLSearchParams();
    params.append('currentPage',1)
    params.append('showCount',10)
    params.append('auth',auth)
    export default {
      name: "my-data",
      data() {
        return{
          parm:{
            currentPage:1,
            showCount:10
          },
          applyData:[],
          imgUrl:[],
          tag:true//防止多次刷新
        }
      },
      methods:{
        back() {
          window.history.back(-1);
        },
        post() {
          let _this = this;
          _this.$ajax({
            url:'/api/customer/applyList.html?channelNum='+channelNum,
            method:'post',
            data:params
          }).then(function(res) {
            console.log('获取借款信息',res)
            _this.applyData = res.data.records
            res.data.records.forEach(function(item,index) {
              if(!item.images){
                _this.imgUrl.push('xxx')
              }else{
                _this.imgUrl.push(JSON.parse(item.images)[0].imageUrl)
              }
            })
            console.log('借款信息循环',_this.applyData)

          }).catch(function(res) {
            console.log('错误')
          })
        }
      },
      mounted() {
        let _this= this
        let screenHeight = document.documentElement.clientHeight;//屏幕高度
        console.log(screenHeight);

        window.addEventListener('scroll',function() {
          let contentHeight = document.querySelector('.my_data_out').offsetHeight;//文档整体高度
          if(screenHeight+document.documentElement.scrollTop>=contentHeight){
            console.log('到底了');
            if(_this.tag == true){
              _this.tag = false;
              _this.parm.currentPage++;
              params.set('currentPage',_this.parm.currentPage)
              _this.$ajax({
                url:'/api/customer/applyList.html?channelNum='+channelNum,
                method:'post',
                data:params
              }).then(function(res) {
                console.log(params.get('currentPage'))
                _this.tag = true
                console.log('后台返回数据',res)
                res.data.records.forEach(function(value,index) {
                  _this.applyData.push(value)
                })
                // res.data.records.forEach(function(item,index) {
                //   if(!item.images){
                //     _this.imgUrl.push('xxx')
                //   }else{
                //     _this.imgUrl.push(JSON.parse(item.images)[0].imageUrl)
                //   }
                // })
              }).catch(function(res) {
                console.log('错误')
              })
            }
          }
        })
        this.post()
      }
    }
</script>

<style scoped>

</style>
<style src="../assets/reset.css"></style>
<style src="../assets/style.css"></style>
